package cn.yunhe.service;

import cn.yunhe.dao.StreetDao;
import cn.yunhe.pojo.Street;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StreetService {
    SqlSession session=null;
    StreetDao streetDao=null;

    /**
     * 初始化
     */
    public void initial(){
        session=SqlSessionFactoryUtil.getSqlSession();
        streetDao=session.getMapper(StreetDao.class);
    }

    /**
     * 销毁
     */
    public void destory(){
        if (session!=null){
            session.commit();
            session.close();
        }
    }

    /**
     * 插入
     * @param street
     * @return
     */
    public boolean insertStreet(Street street){
        initial();
        boolean flag= streetDao.insertStreet(street);
        destory();
        return flag;
    }

    /**
     * 查询
     * @param street
     * @return
     */
    public List<Street> streetList(Street street){
        initial();
        List<Street> streetList=streetDao.streetList(street);
        destory();
        return streetList;
    }

}
